#! encoding=utf-8

import requests
from common import HOST
import traceback


def add(name, rtsp_url, attached_params):
    url = HOST + '/camera'
    print "POST /camera 创建相机 ..."
    ret = None
    try:
        ret = requests.session().post(url, {'name': name, 'url': rtsp_url, 'attached_params': attached_params}).content
    except:
        print traceback.format_exc()
    finally:
        print ret


def get():
    url = HOST + '/camera'
    print "GET /camera 获取所有相机 ..."
    ret = None
    try:
        ret = requests.session().get(url).content
    except:
        print traceback.format_exc()
    finally:
        print ret


def delete(camera_id):
    url = HOST + '/camera/' + camera_id
    print "Delete /camera/{camera_id} 删除单个相机 ..."
    try:
        requests.session().delete(url)
    except:
        print traceback.format_exc()


def getCamera(camera_id):
    url = HOST + '/camera/' + camera_id
    print "GET /camera/{camera_id} 获取单个相机 ..."
    ret = None
    try:
        ret = requests.session().get(url).content
    except:
        print traceback.format_exc()
    finally:
        print ret


def update(camera_id, name, rtsp_url, attached_params):
    url = HOST + '/camera/' + camera_id
    print "PUT /camera/{camera_id} 修改单个相机 ..."
    ret = None
    try:
        ret = requests.session().put(url, {'name': name, 'url': rtsp_url, 'attached_params': attached_params}).content
    except:
        print traceback.format_exc()
    finally:
        print ret